#include <stdio.h>
#include <assert.h>
#include <stdlib.h>

#define MIN_SIZE 1
#define MAX_SIZE 65536

int main (void)
{
	int i = 0;
	int size = 0;
	char * write_buffer = NULL; /* el buffer del cual se va a escribir */
	FILE * fifo = NULL;
	size_t err = 0;
	char go_on = 'a';

	write_buffer = (char *) calloc (MAX_SIZE, sizeof(char));
	assert (write_buffer != NULL);

	for (i=0; i < MAX_SIZE; i++)
		write_buffer[i] = 'a';
;

	/** escribimos con los diferentes tamaños **/
	for (size=MIN_SIZE; size<=MAX_SIZE; size*=2)
	{
		fifo = fopen ("/dev/fifo", "w");
		assert (fifo != NULL);
		printf("size=%d\n", size);
		err = fwrite(write_buffer, sizeof(char), size, fifo);
		assert (err == (size_t) size);
		err = fclose (fifo);
		assert (err == 0);
		scanf("%c", &go_on);
	}

	free(write_buffer);
	write_buffer = NULL;
	
	return 0;
}
